﻿
Imports System.Text
Imports osi.root.connector
Imports osi.root.constants

Public Module operators
    Public Function emptyToString(Of T)(ByVal it As randomAccessIterator(Of T)) As String
        Return Convert.ToString(+it)
    End Function

    Public Function ToString(Of itt, T As randomAccessIterator(Of itt)) _
                            (ByVal f As Func(Of randomAccessIterator(Of itt), String),
                             ByVal start As T,
                             ByVal [end] As T,
                             Optional ByVal seperator As String = character.tab) As String
        k_assert(Not f Is Nothing, "f is not a valid ToStringMethod.")

        Dim rtn As StringBuilder = Nothing
        rtn = New StringBuilder()
        While start <> [end]
            rtn.Append(f(start))
            start += 1
            If start <> [end] Then
                rtn.Append(seperator)
            End If
        End While
        Return Convert.ToString(rtn)
    End Function

    Public Sub vectorInsert(ByVal result As vector(Of String), ByVal entity As String)
        'do not use assert here
        result.push_back(entity)
    End Sub

    Public Sub setInsert(ByVal result As [set](Of String), ByVal entity As String)
        'do not use assert here
        result.insert(entity)
    End Sub

    Public Sub listInsert(ByVal result As list(Of String), ByVal entity As String)
        'do not use assert here
        result.push_back(entity)
    End Sub
End Module
